﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SaleManagement.Models;
using SaleManagement.modules;
using System.Net;
using System.Collections.Specialized;
using System.IO;
using System.Windows.Forms;
using Newtonsoft.Json;

namespace SaleManagement.Controllers
{
    class ShopsController
    {
        private ShopModel ObjShops;
        private usShopInfo frmShop;
        public string mesage = "";
        public ShopsController()
        {
        }
        public void Setform(usShopInfo frm)
        {
            this.frmShop = frm;
        }
        public bool Post_AddShop(string name, string address, string phone, string website, byte[] logo)
        {
            bool treck = false;
            string url = "http://192.168.0.105/sale-server/public/35/shop/register";
            using (WebClient client = new WebClient())
            {
                NameValueCollection postdata = new NameValueCollection()
                {
                    {"name",name},
                    {"address",address},
                    {"phone",phone},
                    {"website",website},
                    {"logo",logo.ToString()}
                };
                String soucer = Encoding.UTF8.GetString(client.UploadValues(url, "POST", postdata));

                bool status = soucer.Contains("status");
                if (status == true)
                {
                    Status_Model stt = JsonConvert.DeserializeObject<Status_Model>(soucer);
                    mesage = stt.Status;
                    treck = true;
                }
                else
                {
                    Error_Model err = JsonConvert.DeserializeObject<Error_Model>(soucer);
                    mesage = err.Error_msg;
                    treck = false;
                }
            }
            return treck;

        }



        
    }
}
